<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<link rel="stylesheet" type="text/css" href="${contextPath}/admin/stylesheets/common.css?v=${sversion}" media="screen" />
	<link rel="stylesheet" type="text/css" href="${contextPath}/admin/stylesheets/table.css?v=${sversion}" media="screen" />
	<script type="text/javascript" src="${contextPath}/ext/jquery/jquery-1.8.1.min.js"></script>
	<script type="text/javascript" src="${contextPath}/ext/jquery_form/jquery.form.min.js"></script>
	<script type="text/javascript" src="${contextPath}/ext/layer/layer.min.js"></script>
	<script type="text/javascript" src="${contextPath}/ext/laydate/laydate.js"></script>
	
	
	<script type="text/javascript" src="${contextPath}/admin/ext/jquery/selectbox.js"></script>
	<script type="text/javascript" src="${contextPath}/admin/ext/zw/check.js?v=${sversion}"></script>
	<script type="text/javascript" src="${contextPath}/admin/javascripts/zcommon.js?v=${sversion}" basepath="${contextPath}" baseinit="ajaxCheckLogin"></script>

</head>
<body>
<div class="place">
    <span class="label-span">位置：</span>
    <ul id="place-list" class="place-ul">
        <li>数据源配置</li>
    </ul>
</div>
<div class="body-warp">
    <div class="panel">
        <div class="panel-title">
            <i class="form-icon"></i>
            <span class="title-text">基本信息</span>
        </div>
        <div class="panel-body">
		    <form id="saveform" method="post">
		    	<input type="hidden" name="id" value="${(obj.id)!}"/>
		        <table class="form-table">
		        	<tr>
                        <td><label class="form-label">数据源名称：<b class="red">*</b></label></td>
                        <td>
                            <input class="form-control" name="name" value="${(obj.name)!}" data-check="must|max-len:100" type="text" />
                        </td>
                    </tr>
		        	<tr>
                        <td><label class="form-label">数据源类型<b class="red">*</b></label></td>
                        <td>
                            <select class="form-select" data-check="must" id="db_type" name="db_type" onchange="dbtype_change();" >
                                <option value="1" <#if (obj.db_type)??&&obj.db_type==1>selected="selected"</#if> >MYSQL</option>
                                <option value="2" <#if (obj.db_type)??&&obj.db_type==2>selected="selected"</#if>>SQLSERVER</option>
                                <option value="3" <#if (obj.db_type)??&&obj.db_type==3>selected="selected"</#if>>ORACLE</option>
                                <option value="4" <#if (obj.db_type)??&&obj.db_type==4>selected="selected"</#if>>HTTP接口</option>
                            </select>
                        </td>
                    </tr>
                    <tr class="dbtype type_db">
                        <td><label class="form-label">数据库IP<b class="red">*</b></label></td>
                        <td>
                            <input class="form-control" name="db_ip" data-check="max-len:100" value="${(obj.db_ip)!}" type="text" />
                        </td>
                    </tr>
                    <tr class="dbtype type_db">
                        <td><label class="form-label">数据库端口<b class="red">*</b></label></td>
                        <td>
                            <input class="form-control" name="db_port" data-check="n|max-len:100" value="${(obj.db_port)!}" type="text" />
                        </td>
                    </tr>
                    <tr class="dbtype type_db">
                        <td><label class="form-label">数据库名称<b class="red">*</b></label></td>
                        <td>
                            <input class="form-control" name="db_name" data-check="max-len:100" value="${(obj.db_name)!}" type="text" />
                        </td>
                    </tr>
		        	<tr class="dbtype type_db">
                        <td><label class="form-label">数据库帐号<b class="red">*</b></label></td>
                        <td>
                            <input class="form-control" name="db_account" data-check="max-len:100" value="${(obj.db_account)!}" type="text" />
                        </td>
                    </tr>
                    <tr class="dbtype type_db">
                        <td><label class="form-label">数据库密码<b class="red">*</b></label></td>
                        <td>
                            <input class="form-control" name="db_password" data-check="max-len:100" value="${(obj.db_password)!}" type="text" />
                        </td>
                    </tr>
                    <tr class="dbtype type_db">
                        <td><label class="form-label">数据库表名<b class="red">*</b></label></td>
                        <td>
                            <input class="form-control" name="table_name" data-check="max-len:100" value="${(obj.table_name)!}" type="text" />
                        </td>
                    </tr>
                    <tr class="valign-top dbtype type_db">
                        <td><label class="form-label">数据库基础查询sql<b class="red">*</b></label></td>
                        <td>
                            <textarea class="form-textarea" name="db_sql" data-check="max-len:5000" >${(obj.db_sql)!}</textarea>
                            <span class="form-tip alert alert-info">
                                                                可用“{sql}”占位“自增字段大于目标库最大值（例如：“id>1”）”语句位置\n
                            </span>
                        </td>
                    </tr>
                    <tr class="dbtype type_http">
                        <td><label class="form-label">HTTP接口地址<b class="red">*</b></label></td>
                        <td>
                            <input class="form-control" name="http_url" data-check="max-len:100" value="${(obj.http_url)!}" type="text" />
                        </td>
                    </tr>
                    <tr>
                        <td><label class="form-label">排序自增字段<b class="red">*</b></label></td>
                        <td>
                            <input class="form-control" name="order_field" data-check="must|max-len:100" value="${(obj.order_field)!}" type="text" />
                        </td>
                    </tr>
                    <tr>
                        <td><label class="form-label">字段类型<b class="red">*</b></label></td>
                        <td>
                            <select class="form-select" data-check="must" name="field_type" >
                                <option value="">--请选择--</option>
                                <option value="1" <#if (obj.field_type)??&&obj.field_type==1>selected="selected"</#if>>数值</option>
                                <option value="2" <#if (obj.field_type)??&&obj.field_type==2>selected="selected"</#if>>文本</option>
                            </select>
                        </td>
                    </tr>
                    
		            <tr>
		                <td><label class="form-label">&nbsp;</label></td>
		                <td>
		                    <input class="btn btn-success btn-large" type="button" onclick="_save()" value="提交">
		                    <input class="btn btn-danger btn-large" type="reset" value="重置">
		                    <input class="btn btn-primary btn-large" type="button" onclick="_back();" value="返回" >
		                </td>
		            </tr>
		        </table>
		    </form>
        </div>
<script type="text/javascript">
var prefix = "${contextPath}";

function dbtype_change(){
    var db_type = $("#db_type").val();
    if(db_type){
        $(".dbtype").attr("style","display:none;");
        if(db_type==1 || db_type==2 || db_type==3){
            $(".type_db").removeAttr("style");    
        }else if(db_type==4){
            $(".type_http").removeAttr("style");
        }
    }
}

dbtype_change();

function _save() {
	
	var url = '${contextPath}/dbInfo/modify' ;
	if($('#saveform').check()){
		var post = $('#saveform').serialize();
		if(!confirm("确定提交？")) return false;
		$.post(url,post,function(data){
			if(1==data.s){
				alert(data.d||"操作成功");
				parent.grid.refresh();
				_back();
			}else{
				alert(data.d||"操作失败");
			}
		},"json");
	}
}

function _back(){
    parent.layer.closeAll();
}
$(document).ready(function(){
	
	// 解决IE6下第二次打开弹窗时焦点丢失的问题
	$('#form :input:not(:hidden):not(:button):first').focus();
});
</script>
</body>
</html>